﻿package org.ilanchong.droidcontroller.ui;

import org.ilanchong.droidcontroller.ControlCommand;
import org.ilanchong.droidcontroller.DroidController;
import org.ilanchong.droidcontroller.DroidControllerActivity;
import org.ilanchong.droidcontroller.R;

import android.os.AsyncTask;

public class UpdateCommandUI extends AsyncTask <ControlCommand, Integer, CommandResultInfo> {
	private DroidControllerActivity client;

	public UpdateCommandUI(DroidControllerActivity _androidClient){
		this.client = _androidClient;
	}
	/**
	 * 任务之前
	 */
	@Override
	protected void onPreExecute() {
		this.client.getStatusView().setText(R.string.sending_command);
	}
	
	/**
	 * 后台处理
	 */
	@Override
	protected CommandResultInfo doInBackground(ControlCommand... params) {
		// TODO Auto-generated method stub
		ControlCommand commandArg = params[0];
		return DroidController.sendCommond(commandArg.getComputers(), commandArg.getPort(), commandArg.getCommand() );
	}
	
	/**
	 * 后台任务完成后执行
	 */
	@Override
	protected void onPostExecute(CommandResultInfo result) {
		client.getStatusView().setText(result.getMessage());
	}
	
	/**
	 * 更新进度信息
	 */
	@Override
	protected void onProgressUpdate(Integer... values) {
		super.onProgressUpdate(values);
	}
	
	/**
	 * 取消
	 */
	@Override
	protected void onCancelled() {
		super.onCancelled();
	}
	
}
